using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//ITEM为物品类放入背包 ADD为增益类直接获得
public enum Items { ITEM = 1, ADD = 2 }

public class TouchEvent : MonoBehaviour
{
    [SerializeField] Items Items = Items.ADD;
    public ItemDatas_SO itemDataSO;
    // Start is called before the first frame update
    void Start()
    {
        if (itemDataSO != null)
        {
            GetComponent<SpriteRenderer>().sprite = itemDataSO.itemIcon;
            gameObject.name = itemDataSO.itemName;
        }
    }

    // Update is called once per frame
    void Update()
    {

    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            if (Items == Items.ADD) other.gameObject.GetComponent<DataController>().Heal(1);

            if (itemDataSO != null && Items == Items.ITEM)
            {
                GameManager.Instance.AddItem(itemDataSO);
                //每次添加物品时候直接刷新背包界面
                GameManager.Instance.RefreshBag();


                Destroy(gameObject);
            }

        }
    }
}
